package com.hbmcc.heshenghuo.util

import java.text.DecimalFormat
import java.text.SimpleDateFormat

/**
 * Copyright (c)2017
 * 欣网互联网络科技有限公司
 * author: lpc
 * created on: 2018/5/25 0025
 * description:
 */
object Formatter {
    private val normNumberFormatter = DecimalFormat("######0.00")

    @JvmField
    val ssDateFormatter = SimpleDateFormat("yyyyMMddHHmmss")

    @JvmField
    var msDateFormatter = SimpleDateFormat("yyyyMMddHHmmssSSS")

    private val timeCuFormat = DecimalFormat("######0.0")

    /**
     * 星号化手机号
     */
    @JvmStatic
    fun blurMobile(mobile: String?): String {
        return if (mobile.isNullOrEmpty() || mobile.length < 11) {
            ""
        } else mobile.substring(0, 3) + "****" + mobile.substring(7)
    }

    /**
     * 格式化流量单位
     */
    @JvmStatic
    fun flowUnitM2G(flux: Double): String {
        val strFlux = if (flux / 1024 >= 1) normNumberFormatter.format(flux / 1024) + "GB"
        else normNumberFormatter.format(flux) + "MB"

        return if (strFlux.startsWith(".")) "0$strFlux" else strFlux
    }

    /**
     * 格式化流量单位
     */
    @JvmStatic
    fun unitSecond(time: Long): String {
        val strFlux =  timeCuFormat.format((System.currentTimeMillis() - time) / 1024.0)

        return if (strFlux.startsWith(".")) "0$strFlux" else strFlux
    }





}